/**
 *
 */
package com.angel.common.providers.managers;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

import com.angel.annotation.managers.AnnotationManager;
import com.angel.common.helpers.AnnotationHelper;
import com.angel.common.helpers.ReflectionHelper;


/**
 * @author William
 *
 */
public class MethodExcludeValueAnnotationManager extends AnnotationManager{

	//private static final Class<MethodExcludeValue> METHOD_EXCLUDE_VALUE_ANNOTATION = MethodExcludeValue.class;
	protected static final String METHOD_EXCLUDE_VALUE_ANNOTATION_ACTION = "METHOD_EXCLUDE_VALUE_ANNOTATION_ACTION";

/*
	{
		super.addAction(METHOD_EXCLUDE_VALUE_ANNOTATION_ACTION, new AnnotationAction(){
			@Override
			public Boolean canDoActionFor(AnnotationManager annotationManager, Object object) {
				Method[] methods = ReflectionHelper.getAllMethodWith(annotationManager.getClassAnnotation(), object.getClass());
				Boolean canDoAction = false;
				if(methods!= null && methods.length == 1 && methods[0].getParameterTypes().length == 0){
					canDoAction = true;
				}
				return canDoAction;
			}

			@Override
			public Object doAction(AnnotationManager annotationManager, Object object) {
				Method[] methods = ReflectionHelper.getAllMethodWith(annotationManager.getClassAnnotation(), object.getClass());
				Comparable<?> comparable = (Comparable<?>) ReflectionHelper.invokeMethodWithoutParameters(object, methods[0]);
				return comparable;
			}

			@Override
			public Boolean isDefault() {
				return true;
			}

		}
		);

	}*/

	public Comparable<?> getExcludeValueFor(Object object) {
		/*if(!super.containsAction(METHOD_EXCLUDE_VALUE_ANNOTATION_ACTION)){
			throw new AnnotationManagerException("Object [" + object.toString() + "] not contains annotation [" + this.getClassAnnotation().getSimpleName() + "] to be processed.");
		}
		return (Comparable<?>) super.processAnnotation(object);*/
		return null;
	}

	@Override
	public Boolean canProcessAnnotationAt(Object object) {
		return	AnnotationHelper.hasAnnotation(ReflectionHelper.getMethods(object), this.getClassAnnotation()) &&
				AnnotationHelper.hasOnlyOneAnnotationInstance(ReflectionHelper.getMethods(object), this.getClassAnnotation());
	}

	@Override
	protected Annotation getAnnotationImpl(Object object) {
		Method method = null;
		if(this.canProcessAnnotationAt(object)){
			method = ReflectionHelper.getAllMethodWith(this.getClassAnnotation(), object.getClass())[0];
		}
		return (method != null) ? method.getAnnotation(this.getClassAnnotation()) : null;
	}

	@Override
	public Class<? extends Annotation> getClassAnnotation() {
		return null;//METHOD_EXCLUDE_VALUE_ANNOTATION;
	}

}
